
//
//  HomePageViewModel.swift
//  民生生活
//
//  Created by apple on 2017/8/7.
//  Copyright © 2017年 youjindi.app.com. All rights reserved.
//

import UIKit
import Result
import ReactiveSwift

class HomePageViewModel: BaseViewModel {

    var checkForTrainAction : Action<Void, Void, NoError>
    var checkForBreakRule : Action<Void, Void, NoError>
    var checkForPayForPhone : Action<Void, Void, NoError>
    var checkForPayForPhoneData : Action<Void, Void, NoError>
    
    override init() {
        
        self.checkForTrainAction = Action(execute: { (_) -> SignalProducer<Void, NoError> in
            let vc = TrainController()
            getNavigation().pushViewController(vc, animated: true)
            return SignalProducer.empty
        })
        
        self.checkForBreakRule = Action(execute: { (_) -> SignalProducer<Void, NoError> in
            let vc = TrainController()
            getNavigation().pushViewController(vc, animated: true)
            return SignalProducer.empty
        })
        
        self.checkForPayForPhone = Action(execute: { (_) -> SignalProducer<Void, NoError> in
            let vc = PayForPhone()
            getNavigation().pushViewController(vc, animated: true)
            return SignalProducer.empty
        })
        
        self.checkForPayForPhoneData = Action(execute: { (_) -> SignalProducer<Void, NoError> in
            let vc = PayForPhoneData()
            getNavigation().pushViewController(vc, animated: true)
            return SignalProducer.empty
        })
    }
    
    func getHeadImageArray(completion:@escaping ((Array<Any>) -> ())) -> Void{
        getDataWithGet(url: AdvListUrl) { (data) in

            let dic = data as! [String:AnyObject?]
            let ora = dic["result"] as! Array<Any>
            
            for index in ora{
                let model = HomePageModel(dic: index as! [String : String])
                self.dataArray.append(model)
            }
            
            completion(self.dataArray)
        }
    }

}
